package cn.kgc.mcartoon.controller;

import cn.kgc.mcartoon.condition.CartoonCondition;
import cn.kgc.mcartoon.constans.Constants;
import cn.kgc.mcartoon.dto.CartoonDto;
import cn.kgc.mcartoon.dto.HotDto;
import cn.kgc.mcartoon.dto.ResultDto;
import cn.kgc.mcartoon.entity.MmCartoonClassificationDicDO;
import cn.kgc.mcartoon.entity.MmCartoonDO;
import cn.kgc.mcartoon.mapper.MmCartoonClassificationDicMapper;
import cn.kgc.mcartoon.service.MmCartoonClassificationDicService;
import cn.kgc.mcartoon.service.MmCartoonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "网站首页",produces = "网站首页MmHomeController")
@RestController
@RequestMapping("/api/home")
public class MmHomeController {

    @Autowired
    private MmCartoonService cartoonService;

    @Autowired
    private MmCartoonClassificationDicService classificationDicService;

    @ApiOperation(value = "原创精品")
    @GetMapping("original")
    public ResultDto queryCartoonOrigainal(){

        CartoonCondition condition = new CartoonCondition(Constants.Cartoon.Sort.HOT,Constants.Home.INIT,Constants.Home.FINISH_SIZE);

        List<CartoonDto> cartoons = cartoonService.selectOriginalList(condition);

        if (!CollectionUtils.isEmpty(cartoons)){
            return ResultDto.ok(cartoons);
        }else{
            return ResultDto.error("没有查到数据");
        }
    }

    @ApiOperation(value = "热门排行")
    @GetMapping("hot")
    public ResultDto queryCartoonHot(){

        CartoonCondition condition = new CartoonCondition(Constants.Cartoon.Sort.HOT,Constants.Home.INIT,Constants.Home.FINISH_SIZE);
        List<HotDto> hotDtos = cartoonService.selectHotList(condition);

        if (!CollectionUtils.isEmpty(hotDtos)){
            return ResultDto.ok(hotDtos);
        }else{
            return ResultDto.error("没有查到数据");
        }

    }

    @ApiOperation(value = "漫画分类")
    @GetMapping("classify_tree")
    public ResultDto classifyTree(){

        ResultDto resultDto = classificationDicService.selectCartoonClass();

        return resultDto;


    }
}
